﻿import interfaces = require("Interfaces");

var applicationInternal: kendo.mobile.Application;

export function getApplication() {
    var appWindow = getIWindow();
    if (appWindow.app === undefined || appWindow.app.application === undefined) {
        var app: any = {};
        applicationInternal = app.application = generateNewApplication();
        appWindow.app = app;
    } else {
        applicationInternal = <kendo.mobile.Application>appWindow.app.application;
    }

    return applicationInternal;
}

export function getIWindow() {
    var appWindow: interfaces.IAppWindow = window;
    return appWindow;
}

export function getAppInitProperty() {
    var appWindow = getIWindow();
    var appInit = appWindow.appInit = appWindow.appInit || {};
    return appInit;
}

export function getViewDataProperty() {
    var appWindow = getIWindow();
    var viewData = appWindow.viewData = appWindow.viewData || {};
    return viewData;
}

function generateNewApplication() {
    return new kendo.mobile.Application($(document.body),
        {
            transition: 'slide',
            platform: 'ios',
            skin: "flat",
        });
}